layui.define(['table', 'jquery', 'element'], function (exports) {
    "use strict";

    var MOD_NAME = 'pearFly',
        $ = layui.jquery;

    var pearFly =new function () {
        this.get = function(option){

            $.ajax({
                  url:option.url,
                  data:option.data?option.data:{},
                  dataType:'json',
                  type:'get',
                  async:option.async?option.async:'true',
                  success:option.success?option.success:function(){},
                  failure:option.failure?option.failure:function(){}
            })
        }

        this.post = function(option){

            var data = option.data;
            var contentType = "application/x-www-form-urlencoded; charset=UTF-8";

            if(option.type=='json'){

                data =  JSON.stringify(data);

                contentType = "application/json; charset=UTF-8";
            }

            $.ajax({
                url:option.url,
                data:data,
                dataType:'json',
                type:'post',
                contentType: contentType,
                async:option.async?option.async:'true',
                success:option.success?option.success:function(){},
                failure:option.failure?option.failure:function(){}
            })
        }

        this.delete = function(option){

            var data = option.data;
            var contentType = "application/x-www-form-urlencoded; charset=UTF-8";

            if(option.type=='json'){

                data =  JSON.stringify(data);

                contentType = "application/json; charset=UTF-8";
            }

            $.ajax({
                url:option.url,
                data:data,
                dataType:'json',
                type:'delete',
                contentType: contentType,
                async:option.async?option.async:'true',
                success:option.success?option.success:function(){},
                failure:option.failure?option.failure:function(){}
            })
        }
    };

    exports(MOD_NAME,pearFly);
})